package org.demis.dwarf.core.mapping;

import org.demis.dwarf.core.db.Column;
import org.demis.dwarf.core.db.Table;
import org.demis.dwarf.core.object.Entity;
import org.demis.dwarf.core.object.RawAttribute;

import java.util.HashMap;
import java.util.Map;

public class DB2ObjectMapping {

    private static DB2ObjectMapping instance = new DB2ObjectMapping();

    private Map<Table,Entity> tableToEntity = new HashMap<Table, Entity>();
    private Map<Entity, Table> entityToTable = new HashMap<Entity, Table>();

    private Map<Column, RawAttribute> columnToAttribute = new HashMap<Column, RawAttribute>();
    private Map<RawAttribute,Column> attributeToColumn = new HashMap<RawAttribute, Column>();


    public static DB2ObjectMapping getInstance() {
        return instance;
    }

    public void addMapping(Table table, Entity entity) {
        tableToEntity.put(table, entity);
        entityToTable.put(entity, table);
    }

    public Table getTable(Entity entity) {
        return entityToTable.get(entity);
    }

    public Entity getEntity(Table table) {
        return tableToEntity.get(table);
    }

    public void addMapping(Column column, RawAttribute rawAttribute) {
        columnToAttribute.put(column, rawAttribute);
        attributeToColumn.put(rawAttribute, column);
    }

    public Column getColumn(RawAttribute rawAttribute) {
        return attributeToColumn.get(rawAttribute);
    }

    public RawAttribute getRawAttribute(Column column) {
        return columnToAttribute.get(column);
    }

}
